package com.waiter.moximoxi.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.waiter.moximoxi.R;

import cn.yhong.aframework.dialog.BaseDialog;
import cn.yhong.aframework.listener.OnCallbackListener;
import cn.yhong.aframework.utils.AtyUtils;

/**
 * Created by 17639 on 2020/10/15.
 */

public class CollectionDialog extends BaseDialog implements View.OnClickListener {

    private ImageView dialog_collection_dis;
    private TextView dialog_collection_title;
    private TextView dialog_need_collection_tv;
    private EditText et_feed_back_title;
    private TextView scan_code_tv;

    public CollectionDialog(Context context, OnCallbackListener onCallbackListener) {
        super(context, onCallbackListener);
    }

    @Override
    public Dialog initDialog(Context context) {
        View view = View.inflate(context, R.layout.dialog_collection, null);
        dialog_collection_dis = view.findViewById(R.id.dialog_collection_dis);
        dialog_collection_title = view.findViewById(R.id.dialog_collection_title);
        dialog_need_collection_tv = view.findViewById(R.id.dialog_need_collection_tv);
        et_feed_back_title = view.findViewById(R.id.et_feed_back_title);
        scan_code_tv = view.findViewById(R.id.scan_code_tv);

        dialog_collection_dis.setOnClickListener(this);
        scan_code_tv.setOnClickListener(this);

//        et_feed_back_title.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//
//            }
//
//            @Override
//            public void afterTextChanged(Editable editable) {
//                if(!TextUtils.isEmpty(editable.toString().trim())){
//                    String editStr = editable.toString().trim();
//
//                    int posDot = editStr.indexOf(".");
//                    //不允许输入3位小数,超过三位就删掉
//                    if (posDot < 0) {
//                        return;
//                    }
//                    if (editStr.length() - posDot - 1 > 2) {
//                        editable.delete(posDot + 3, posDot + 4);
//                    } else {
//
//                    }
//                }
//            }
//        });

        return initMatchWrapDialog(view, context, Gravity.CENTER, android.R.style.Animation_InputMethod);
    }

    public void showCollectionDialog(String title, String price) {

        if(title.equals("刷卡")){
            scan_code_tv.setText("刷卡");
        }

        dialog_collection_title.setText(title);
        dialog_need_collection_tv.setText("应收:" + price + "元");
        showDialog();
    }


    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_collection_dis:
                break;
            case R.id.scan_code_tv://扫码
                if (TextUtils.isEmpty(AtyUtils.getText(et_feed_back_title))) {
                    AtyUtils.showShort(context, "请输入金额", true);
                    return;
                }
                onCallbackListener.onCallback(0, AtyUtils.getText(et_feed_back_title));
                et_feed_back_title.setText("");
                break;
        }
        dismissDialog();
    }


}
